package cn.heantai;

import java.io.File;
import java.io.IOException;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import de.mindpipe.android.logging.log4j.LogConfigurator;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;

/**工程在模拟器中运行时，一直报file无法找到，权限拒绝，在真机中运行无此问题*/
public class AndroidLog4jActivity extends Activity {
	final LogConfigurator logConfigurator = new LogConfigurator();
	
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        File file=new File(Environment.getExternalStorageDirectory() + "/myapp.log");
        if(!file.exists()){
        	try {
				file.createNewFile();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        }
        logConfigurator.setFileName(Environment.getExternalStorageDirectory() + "/myapp.log");
        logConfigurator.setRootLevel(Level.DEBUG);
        // Set log level of a specific logger
        logConfigurator.setLevel("org.apache", Level.ERROR);
        logConfigurator.configure();
        

        log.info("This message should be seen in log file and logcat");
    }
    
private final Logger log = Logger.getLogger(AndroidLog4jActivity.class);
	
	public void myMethod() {
		log.info("This message should be seen in log file and logcat");
	}
}